package com.leyou.item.controller;

import com.leyou.item.pojo.SpecGroupDTO;
import com.leyou.item.pojo.SpecParamDTO;
import com.leyou.item.service.SpecGroupService;
import com.leyou.item.service.SpecParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("spec")
public class SpecGroupController {

    @Autowired
    SpecGroupService specGroupService;
    @Autowired
    SpecParamService specParamService;

    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCategory(@RequestParam("id") Long id){
        return ResponseEntity.ok(specGroupService.queryGroupByCategory(id));
    }

    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> findSpecParamsByGid(
            @RequestParam(name = "gid",required = false) Long gid,
            @RequestParam(name = "cid",required = false) Long cid,
            @RequestParam(name = "searching",required = false) Boolean searching
    ){
        return ResponseEntity.ok(specParamService.querySpecParams(gid,cid,searching));
    }

    @GetMapping("/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsByCid(@RequestParam("id") Long id){
        return ResponseEntity.ok(specGroupService.querySpecsByCid(id));
    }
}